#include "pch.h"
#include "seEgg.h"

void seEgg::Init(int sX, float velocity,int type)
{	
	mSprite.SetPosition(sX,0);
	mVelocity = velocity;
	mType = type;
	fAngle=0.0f;
	mDying = false;
	mScale = 0.1f;
	mFallen = false;
}

void seEgg::Step()
{
	if(!mDying)
	{
		float x= mSprite.GetPosition().x;
		float y= mSprite.GetPosition().y;
		mSprite.SetPosition(x,y+mVelocity);
		mCircleSprite.SetCenter(mSprite.GetSize().x / 2, mSprite.GetSize().y / 2);

		fAngle += ONE_FRAME_DURATION*5.0f;
		if (fAngle > 100.0f) fAngle = 0.0f;
		mSprite.SetRotation( 10*sin(fAngle) );
	}
	else
	{
		mScale = mScale + ONE_FRAME_DURATION * 2;

		if(mScale > 1)
			mScale = 1;
	}
}

void seEgg::Draw()
{	

	if(mDying)
	{
		mCircleSprite.SetScale(mScale,mScale);
		if(!mFallen)
			mCircleSprite.SetColor(sf::Color(255,255,255,int(255 - mScale * 255)));
		else
			mCircleSprite.SetColor(sf::Color(255,0,0,int(255 - mScale * 255)));

		mCircleSprite.SetPosition(mSprite.GetPosition().x, mSprite.GetPosition().y);
		app.Draw(mCircleSprite);
	}
	else
	{

		app.Draw(mSprite);

	}
}